/**
 * 功能描述
 */
define(function (require, exports, module) {
	var Component = require("subnav");
	var aw = require("ajaxwrapper");
	var procWel = require("../constant/fetchProperties");
	var user = require("store").get("user");
	
    var instance = {
        initComponent: function (params, widget) {
            var component = new Component({
            	parentNode:".J-subnav",
				model : {
					title:"消费卡",
					items : [{
        				id:"search",
        				type:"search",
        				placeholder:"会员/卡号/证件号",
        				handler : function(str){
        					var grid = widget.get("grid");
        					var subnav = widget.get("subnav");
        					aw.ajax({
        						url:"api/cate/travelaccount/search*",
        						data:{
        							s:str,
        							searchProperties: "roomPersonalInfo.personalInfo.name," +
        									"roomPersonalInfo.personalInfo.idNumber," +
        									"roomPersonalInfo.consumeCard.cardNumber",
                        			"orderString" : "creatDate:desc",
        							fetchProperties:procWel.fetchProperties
        						},
        						dataType:"json",
        						success:function(data){
        							grid.setData(data);
        						}
        					});
        				}
					},{
					    id :"servicePoint",
					    type : "buttongroup",
					    all : {
					     show:false,
					  	 first:true
					    },
					    tip : "服务点",
					    keyField :"pkServicePoint",
					    valueField : "name",
					    items:user.privateServicePoints,
//					    url : "api/servicepoint/operableservicepoints",
					    params : function(){
					     return{
					    	 fetchProperties:"pkServicePoint,name"
					     }
					    },
					    handler : function(key,element){
					    	  widget.get("grid").refresh();
					    }
					},{
						id : "status",
						tip:"状态",
						type:"buttongroup",
						items:[{
							key:"",
							value:"全部"
						},{
							key:"Effective",
							value:"有效"
						},{
							key:"Lose",
							value:"挂失"
						},{
							key:"Returned",
							value:"退卡"
						}],
						handler:function(key,element){
							widget.get("grid").refresh();
						}
					},{
						id : "grantDate",
						type : "daterange",
						tip:"发卡日期",
						ranges : {
			                "本月": [moment().startOf("month"), moment().endOf("month")]
						},
						defaultRange: "本月",
						handler : function(time){
							 widget.get("grid").refresh();
						}
					},{
						id : "operateDate",
						type : "daterange",
						tip:"发放时间",
						ranges : {
			                "本月": [moment().startOf("month"), moment().endOf("month")]
						},
						defaultRange: "本月",
						show:false,
						handler : function(time){
							 widget.get("detailGrid").refresh();
						}
					},{
        				id : "add",
						type : "button",
						text:"发卡",		
						handler:function(){
							widget.handler.subnavHandler.grantCard(widget);
						}
					},{
            			id : "return",
    					type : "button",
    					text:"返回",						
    					show : false,
    					handler:function(){
    			    		widget.show(".J-grid").hide(".J-detailgrid");
    			    		widget.get("subnav").hide(["return","operateDate"]).show(["search","status","grantDate","add"]);
    					}
					}]
				}
            });
            widget.set("subnav", component);
        }
    };
    module.exports = instance;
});
